home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TPP112.ARJ / TPP.DOC < prev    next >
Text File  |  1992-04-18  |  19KB  |  445 lines

  1. ----------------------------------------------------------------------
  2. 04/18/92        Turbo Pascal Pre-Processor         All Rights Reserved
  3. Copyright (c) 1991-1992 by SupremeSoft                Version 1.12
  4. ----------------------------------------------------------------------
  5.  
  6. Introduction
  7. ------------
  8.  
  9. What is TPP? TPP is a pre-processor designed to work with Turbo Pascal. 
  10. Many programmer's who are both C and Pascal programmers find that they 
  11. miss C's pre-processing capabilities. 
  12.  
  13. In addition, professional Pascal programmers find it quite absurd to 
  14. declare constants for such mundane things as maximum values for array 
  15. indexes. This adds to the programs code size, as well as wasting precious 
  16. memory. Why declare a constant when you'll only be using it as a fixed 
  17. value, which the compiler can determine at compile-time as it is?
  18. In C, all you need to do is use the pre-processor to define this
  19. value. (The question of why use constants at all comes up. Especially if 
  20. they are useful, but wasteful of resources. Most languages use constants, 
  21. whereas C and C++ provide macro equivalents, and thus have no constant 
  22. keywords) 
  23.  
  24. Finally, Turbo Pascal has a gotcha for all constants. They sit in your 
  25. data segment. Turbo Pascal, though smart in some ways, is not smart 
  26. enough to know that this constant is only a "hard coded" value, and will 
  27. thus not replace all references for that constant with its definition.
  28. Besides this, there is a big caveat for using constants as initializers.
  29. Reading your Turbo Pascal manual carefully, you will see that any constant
  30. is only initialized ONCE. Even if it is declared in a procedure, it is only
  31. initialized ONCE, and lives in the data segment and NOT the procedures local
  32. call stack!
  33.  
  34. In comes TPP. TPP will take your simple constants and replace all 
  35. occurrences of that constant with its definition. Besides that, TPP can 
  36. be used to abbreviate coding declarations which will later be expanded at 
  37. compile time. 
  38.  
  39. -----------------
  40. How to use TPP
  41. -----------------
  42.  
  43. TPP was designed to allow you to use the same source code that you would 
  44. normally use, but also allow you to use TPP keywords. In addition, TPP 
  45. works exactly like the Turbo Pascal Compiler. It will not recompile units 
  46. that do not need to be. (Although, it is not as smart as the Turbo 
  47. compiler as you will see later) 
  48.  
  49. TPP scans your source, looking for a {#DEFINE} statement. This is the 
  50. signal to TPP that a macro definition is about to start. After this comes 
  51. the regular constant definition. For example: 
  52.  
  53.   Normal source:    Const
  54.                         UpperLimit = 3;   {This is the upper limit}
  55.                         LowerLimit = -1;  {This is the lower limit}
  56.  
  57.  
  58.   To adapt to TPP:  Const
  59.                       {#DEFINE} UpperLimit = 3;   {This is the upper limit}
  60.                       {#DEFINE} LowerLimit = -1;  {This is the lower limit}
  61.                                  
  62. Using this {#DEFINE} statement, your source will compile under Turbo as
  63. usual, but can also be compiled using TPP. You do not need to keep two
  64. different sets of source code.
  65.  
  66. That is all there is to it. Now, every occurrence of UpperLimit will be 
  67. replaced by a "3". You can also define string constants etc. In short any 
  68. constant that will work for the Turbo compiler will work for TPP. 
  69.  
  70. Initialized constants, will *NOT* work in TPP, and should be avoided 
  71. during regular use of the Turbo compiler. Initialized constants have 
  72. numerous flaws and many, many gotchas. (Contact us for more detailed 
  73. information on why not to use initialized constants) For example, the 
  74. following is *NOT* legal for TPP: 
  75.  
  76.         Const
  77.           {#Define} LowerLimit : Byte  = -1;  {This is the lower limit}
  78.                   
  79.  
  80. You may use TPP to ease your coding a bit, by using the TPP macro feature 
  81. as you would normal text macros. For instance: 
  82.  
  83.       {#DEFINE} DOS =  Intr(21h);
  84.  
  85. Then, in your code, you may say:  DOS;  {Call DOS} 
  86. and TPP will change this to    :  Intr(21h);  {Call DOS} 
  87.  
  88. Note that TPP can thus be used for other things than just constants!
  89. {#DEFINE} statements may be used anywhere in your source code.
  90.  
  91. And of course, TPP is not case sensitive.
  92.  
  93. -------------
  94. Limitations
  95. -------------
  96.  
  97.  
  98. TPP is not like the C macro pre-processor. You may not pass variables in 
  99. or out, nor do arithmetic expressions. For example, the following are 
  100. accepted, but are probably not what you want the macro to do:
  101.  
  102.    1.    {#DEFINE} TWICE(X) = X*X;
  103.    2.    {#DEFINE} HIGH(X) = Odd(X) < Even (X);
  104.    3.    {#DEFINE} Limits = 32 * MaxValue;
  105.                      
  106. For definition 1, you would need to have a statement of: TWICE(Z);
  107. Expansion then becomes: X*X;
  108. You probably want: Z*Z;
  109.  
  110. For definition 2, you would need to have a statement of: HIGH(Z);
  111. Expansion then becomes: Odd(X) < Even(X);
  112. You probably want: Odd(Z) < Even(Z);
  113.  
  114. For definition 3, you would need to have a statement of: Limits;
  115. Expansion then becomes: 32 * MaxValue;
  116. Note:  This is not evaluated at macro definition time, unlike in C.
  117.        However, Turbo will usually evaluate it at compile-time, so this
  118.        is actually a GOOD use for TPP.
  119.  
  120. You must be careful not to have the macro name anywhere else 
  121. in your source code, or else it will get expanded. (That is rather 
  122. obvious)
  123.  
  124.  
  125. If you use the Const feature of TPP, be careful of the following:
  126.  
  127.        Const
  128.          {#DEFINE} UpperLimit = 3;   {This is the upper limit}
  129.          {#DEFINE} LowerLimit = -1;  {This is the lower limit}
  130.  
  131.        Type 
  132.              .
  133.              .
  134.           
  135.                       
  136. When TPP processes your file, everything but the comments will be 
  137. stripped out, leaving: 
  138.  
  139.        Const
  140.            {This is the upper limit}
  141.            {This is the lower limit}
  142.  
  143.        Type 
  144.              .
  145.              .
  146.  
  147. The Turbo compiler, will *NOT* accept this. There must be something 
  148. following the CONST declaration. Be aware of this problem. The only real 
  149. work around is to comment out the CONST statement. (This may changed
  150. in later versions of TPP)
  151.  
  152. -------------
  153. How TPP works
  154. --------------
  155.  
  156.  
  157. TPP will scan your source file looking for {#DEFINE} statements or macro 
  158. names. It handles Units just like the Turbo compiler, and looks for a 
  159. USES keyword. If it finds one, it suspends processing of the current file 
  160. and looks at the last file in the USES list. (Just as the Turbo compiler 
  161. does) If the TPU for that file is older than the file, TPP will process 
  162. that file. This is done for all Units in the USES list. 
  163.  
  164. You may define a macro in one unit, and use it in another, as long as 
  165. that unit is listed in the second file's USES list. Confused? Follow the 
  166. same programming style as you do regularly. TPP needs no change in 
  167. programming! It will allow you to treat your source the same way as Turbo 
  168. does. Consider the following:
  169.  
  170. Unit 1;
  171.  ...
  172. {Not the next line can be in either the interface OR the implementation
  173.  section. Either way it will be visible to other units using this unit}
  174.  
  175.  {#DEFINE} Upper = 99;
  176.  
  177. Unit 2;
  178.  
  179.  Uses Unit 1;
  180.  
  181. ...
  182.  
  183. Var t : array[1..Upper] of real;
  184.  
  185.  
  186. Even though Unit2 doesn't declare Upper, it can still use it.
  187. ------------------------------------------------------------------
  188. One major flaw in TPP:
  189.    If Unit1 does NOT need re-compiling, then the macro Upper will never
  190.    get defined for TPP!
  191. -------------------------------------------------------------------
  192.  
  193. Once TPP encounters a macro, it stores the macro name, and its 
  194. corresponding definition. In all later files, any time the macro name is
  195. detected, it will get replaced with the definition. Once TPP reads the 
  196. macro, it will remove it from the source file. Thus causing the Turbo 
  197. compiler to "ignore" the macro, since it isn't there. 
  198.                                            
  199. TPP will scan all the files needed, but will only produce a new file if 
  200. any changes are made to the original source. Depending on the mode of 
  201. operation, this new file will either overwrite the original source file, 
  202. be named DUM?.PAS or will be erased once the program terminates. 
  203.  
  204. Once TPP completes pre-processing the main file and all of its 
  205. corresponding units, it will invoke the Turbo Pascal compiler. Turbo will 
  206. then work with the TPP processed files and any others it needs. 
  207.  
  208. TPP will report on the number of lines it has processed, and the time it 
  209. took to complete the processing. You should find that TPP blazes through 
  210. your files, and only slows once it encounters a macro definition, or a 
  211. macro expansion. 
  212.  
  213. ----------
  214. Specifics
  215. ----------
  216.  
  217.  
  218. Calling Syntax:   TPP  filename[.PAS] [/O | /N | /E] [Turbo Options]
  219.  
  220. Where:   /O    Indicates overwrite source files 
  221.          /N    Indicates no compile after processing
  222.          /E    Indicates execute an editor BEFORE Turbo compiles
  223.  
  224.          Turbo Options  are any Turbo Pascal options you wish to 
  225.          use and they are passed directly on to the compiler.
  226.  
  227.          You may opt to leave off the PAS extension, TPP will add it.
  228.  
  229.          The filename *MUST* be in the current directory, otherwise
  230.          the program will abort immediately. (Other files may be anywhere)
  231.  
  232.  
  233. More:    If you are compling the program, TPP will need to create a
  234.          temporary directory to store the TPP processed files. It 
  235.          is called TPPT, and exists off the current directory.
  236.  
  237.          If you use the /E option then TPP will invoke either the editor
  238.          specified in the EDITOR environment variable, or a default
  239.          editor of Q.EXE (The Qedit editor) BEFORE it calls the Turbo
  240.          compiler. The editor is passed a command line of: *.PAS, and
  241.          thus you may edit all of the TPP processed files. Note that
  242.          only the TPP processed files will be available in the TPPT
  243.          directory. If a file does not get changed by TPP, there is
  244.          no need to make a new copy of it.
  245.  
  246.          Why would you want to call an editor? Well, if you know that
  247.          a file will have illegal syntax after being processed by TPP,
  248.          you can go an correct these errors. Tpyically, once TPP has
  249.          stripped a file of all constants, you are left with a CONST
  250.          keyword, but no definitions. Turbo doesn't like this, and
  251.          executing the editor before compiling allows you to remove
  252.          all the CONST keywords.
  253.  
  254.          Once compilation completes, all TPU and EXE files will be 
  255.          moved to the original directory. If the /O option is 
  256.          specified, then all PAS files will be moved back as well.
  257.  
  258.          If you are not compiling, and have not specified the /O 
  259.          option, then you will be left with some DUM?.PAS files, 
  260.          where ? indicates an integer value. These are the TPP 
  261.          processed files.
  262.  
  263.          If you specify the /O option, then the original source 
  264.          files will be renamed to BAK files, and the TPP processed 
  265.          will be named to the original source files.
  266.  
  267.          When the Turbo compiler is invoked, TPP will attempt to 
  268.          swap out to disk or EMS. If successful, only 1.5K of TPP 
  269.          will be left in memory. If it cannot swap out, it attempts 
  270.          to free up as much memory as it can. This allows TPC to 
  271.          have as much memory available as possible.
  272.  
  273.          When invoked, TPC will be passed the following:
  274.  
  275.                  TPC /M filename [Turbo Options]
  276.  
  277.          Note that it will always be invoked using the /M option!
  278.  
  279. Returns:   The DOS ERRORLEVEL return code will be set as follows:
  280.  
  281.                1      Help screen invoked
  282.                2      File error occurred
  283.                3      Out of memory error
  284.                4      File not in current directory
  285.  
  286.     This may be useful in batch files, or in a MAKE utility.
  287.  
  288. -------------------------
  289. How does TPP find files?
  290. --------------------------
  291.  
  292.  
  293. TPP will attempt to find and read TPC.CFG in order to find out where all 
  294. your source files are located. If it cannot find the source file in the 
  295. current directory, it will then scan the Unit directories listed in 
  296. TPC.CFG. It will *NOT* look on your PATH! 
  297.  
  298. ReadOnly files are valid, and will be processed correctly.
  299.  
  300. ------------------------
  301. Errors and Memory issues
  302. ------------------------
  303.  
  304.  
  305. How much memory does TPP use? That depends on how many macros you define, 
  306. how many unit dependencies you have, and the size of your source. 
  307. Typically, TPP can process up to 50,000 lines in as little as 100K, with 
  308. 300 macros defined. 
  309.  
  310. Upon a memory error, TPP will give you a standard "Out of memory" error.
  311. If this happens, you will have to remove some TSR's to make room. But be 
  312. aware of this, if TPP cannot complete, there is no way TPC will ever be 
  313. able to compile, since it too will usually run out of memory.
  314.  
  315. Upon a file error, TPP will issue a message, asking you to either abort 
  316. or continue. If you abort, you will be asked to confirm it. Then an error 
  317. code will be output, which is the standard IORESULT that any Turbo program 
  318. issues. Look it up in the programmers reference manual. If it is a file 
  319. error, you've got a problem. If it's some other error caused by TPP, 
  320. *please let us know*! 
  321.  
  322. ----------
  323. Warnings
  324. ----------
  325.  
  326.  
  327. Under no circumstances have the word USES anywhere before your actual 
  328. USES statement. TPP is not a compiler, and will treat a USES within a 
  329. comment block to be the keyword it wants. Any time after the original 
  330. USES statement, TPP will ignore the word. Thus, this should NOT happen:
  331.  
  332.       Unit Test;
  333.        {This unit uses two dependencies}
  334.  
  335.       Interface
  336.          Uses DOS,CRT;
  337.       
  338. But, this is legal:
  339.  
  340.       Unit Test;
  341.        {This is a test unit}
  342.  
  343.       Interface
  344.          Uses DOS,CRT;
  345.       
  346.        {This unit uses two dependencies}
  347.  
  348.  
  349. When TPP is run in compilation mode, it needs to create the directory 
  350. TPPT. IF this already exists, you are asked if you wish to use it or not. 
  351. If you answer yes, be aware that if any files already exist in this
  352. directory, TPP will *NOT* overwrite them with new copies. Why? Usually, 
  353. the copies in those directories are identical to the ones about to 
  354. overwrite them. Thus, to save time, TPP reports an error, but does not 
  355. abort operation. 
  356.  
  357. The question comes up, when do I use TPP? Do I develop with it? The 
  358. answer is no. Since TPP lets you use the same source code, develop, test 
  359. and debug using your normal methods. But when it comes time to do a 
  360. production version, run TPP. 
  361.  
  362. Of course, if you are using the macro expansion capabilities, then you 
  363. must use TPP all the time. TPP is not memory resident, and does not 
  364. interface with the Turbo compiler. Therefore, you must use the command 
  365. line compiler. (And no, there are no plans to develop a sophisticated TSR 
  366. version...) 
  367.  
  368. TPP is very fast. It doesn't need to do all that much, but it is a good 
  369. idea to have a nice sized disk cache in place, since a lot of disk 
  370. activity will be apparent. Besides, the Turbo compiler will also be given 
  371. a boost. 
  372.  
  373. -----------------
  374. Savings using TPP
  375. -----------------
  376.  
  377.  
  378. How much do you *really* save using TPP? Honestly, that depends on how 
  379. many CONSTANTs you have in any program. If you program correctly, there 
  380. should be very few, and thus the code size savings are minimal and 
  381. probably not worth it unless you are having a code size contest. Code 
  382. size is hardly affected because now you are substituting a memory 
  383. location for a hard coded value, but the instruction is still coded. 
  384. Thus, the only savings comes from TPP's constant folding and other 
  385. optimizations. 
  386.  
  387. So code size is not a major factor. But memory size is! By using TPP you 
  388. save the memory space needed for all those constants that are being held 
  389. in memory by Turbo Pascal. The more you have, the more you save. This 
  390. should become apparent immediately. 
  391.  
  392. By using the enhanced macro expansion capability of the program, you 
  393. might save some code and memory space, but not much. However you save on 
  394. coding time, another important development factor. 
  395.  
  396. -----------------------------------------------------------------
  397. Warranty and License:
  398. -----------------------------------------------------------------
  399.  
  400.  
  401.         There is NO warranty either expressed or implied. SupremeSoft can 
  402. not be held accountable for anything resulting from the use, or misuse, 
  403. of this program. Your use of this program acknowledges the fact that you 
  404. understand that you are using this program of your own free will, and 
  405. will take any consequences resulting from that action and cannot hole 
  406. SupremeSoft responsible for any reason. 
  407.  
  408.         You are granted a limited license of 30 days to evaluate this 
  409. program. Should you use it beyond that period, you must register your 
  410. copy, or else be in violation of this license agreement. To register, 
  411. send $15.00 to the address below: 
  412.  
  413.  Send a check/money order to the following address:
  414.  
  415.                          SupremeSoft
  416.                          105 Deerfield Drive
  417.                          Easton, CT 06612
  418.                          Re: TPP (1.12)
  419.  
  420.  
  421. You may also contact: msingh@ucs.indiana.edu  if you have access to the
  422. Internet. You can report bugs, problems, pains, antecdotes, etc.
  423.  
  424. ----------------------
  425. Registration benefits
  426. ----------------------
  427.  
  428.                                
  429. TPP will annoy Shareware users. There is an opening random delay, up to 9 
  430. seconds, and there is another delay at the end of the program, before 
  431. you are returned to DOS. (But not before TPC is executed) 
  432.  
  433. Why? It has been our experience that the Shareware concept doesn't work 
  434. as well if one offers no limitations on the program. Thus, rather than 
  435. leaving out features, annoyances are introduced. A lot of time has gone 
  436. into the development of this program, and we feel that users should pay 
  437. for the program if it is of any use to them. 
  438.  
  439. Registered users have no delay's, or requests for key presses. In 
  440. addition, at the time of registration we will send you the absolute 
  441. latest version of the program. After receipt of the program, you may send 
  442. us a SASE disk mailer and receive the next update for free, for the life 
  443. time of the program's development. That's right, for free, as long as you 
  444. pay for postage and provide a mailer. 
  445.